//
//  EInputApp.m
//  AppRanking
//
//  Created by Gang.Wang on 12-11-21.
//  Copyright (c) 2012年 Gang.Wang. All rights reserved.
//

#import "EInputApp.h"
#import "mcf.h"
#import "EGlobalAppData.h"

@interface EInputApp()
{
    UITextView * textView_;
    UIButton * submit_;
}

@property (nonatomic, strong) UITextView * textView;
@property (nonatomic, strong) UIButton * submit;

@end

@implementation EInputApp

@synthesize textView = textView_;
@synthesize submit = submit_;

@synthesize delegate = delegate_;


- (void) dealloc
{
    YRelease(textView_)
    
    [super dealloc];
}



- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        [self privateInit];
    }
    return self;
}

- (id) init
{
    self = [super init];
    if (self)
    {
        [self privateInit];
    }
    
    return self;
}


- (void) reAdjustLayout
{
    [self.submit setFrame:CGRectMake(self.width / 2, (self.height - 60) / 2, self.width / 2, 60)];
    [self.textView setFrame:CGRectMake(0, (self.height - 60) / 2, self.width / 2, 60)];
}


- (void) privateInit
{
    if (self.bInited)
    {
        return;
    }
    
    [self setBackgroundColor:COLOR_SCROLLVIEWTEXTUREDBACKGROUND];
    
    UITextView * temp_textView = [[UITextView alloc] init];
    
    self.textView = temp_textView;
    YRelease(temp_textView)
    [self addSubview:self.textView];
    
    self.submit = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self addSubview:self.submit];
    
    BUTTON_FUNCTION(self.submit, addAppSpy)
    
    [self reAdjustLayout];
    self.bInited = YES;
    
}


- (void) addAppSpy
{
    NSString * appId = self.textView.text;
    
    if ([NSString isNilOrEmpty:appId])
    {
        return;
    }
    
    if ([[[EGlobalAppData sharedInstance] spyAppArray] containsObject:appId])
    {
        [self makeToast:@"已添加过此app"];
        return;
    }
    
    
    [self.textView resignFirstResponder];
    
    
    DELEGATE_CALLBACK(addAppToSpy:, appId);
}

@end
